package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.HomeQo;
import com.qf.staff.common.vo.HomeVo;
import com.qf.staff.service.HomeService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "首页管理Api")
@RestController
@RequestMapping("/home")
public class HomeController {
    @Resource
    HomeService homeService;

    @ApiOperation("查询所有首页信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<HomeVo>> list(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(homeService.list(page, size));
    }

    @ApiOperation("根据id删除首页信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "首页ID")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete")
    public RespResult<Integer> delete(HomeQo homeQoc) {
        return RespResult.success(homeService.delete(homeQoc));
    }

    @ApiOperation("根据ID修改首页信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "首页ID"),
            @ApiImplicitParam(name = "message", value = "首页信息")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(HomeQo homeQoc) {
        return RespResult.success(homeService.modify(homeQoc));
    }

    @ApiOperation("添加首页信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "message", value = "首页信息")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(HomeQo homeQoc) {
        return RespResult.success(homeService.add(homeQoc));
    }
}
